* Clean up
clear all

/* Set working directory: please set your own
cd "~/Dropbox/JOP third submission/JOP replication/"
*/

use 01_data/whole_spain.dta, clear

* 2014/5-2019
reghdfe pp_voteshare post##ep##menorca if period > 1 & ciutadella == 0, absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store twoperiods_ddd_menplcb

* Pre vs. post
reghdfe pp_voteshare post##ep##menorca if ciutadella == 0, absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store prepost_ddd_menplcb

* Fixed effects for each period
reghdfe pp_voteshare post##ep##menorca i.period  if ciutadella == 0, absorb(mesa_code_elecspecific) cluster(mesa_code_elecspecific)
est store threeperiods_ddd_menplcb

* Make table
esttab twoperiods_ddd_menplcb prepost_ddd_menplcb threeperiods_ddd_menplcb using 03_tables/tabled9.tex, tex se replace mtitles ("2014-2019" "2009-2019" "2009-2019")  keep (1.post 1.post#1.ep 1.post#1.menorca 1.post#1.ep#1.menorca 2.period) coeflabels (1.post "2019 election" 1.post#1.ep "EP election in 2019" 1.post#1.menorca "Menorca (outside of Ciutadella) in 2019" 1.post#1.ep#1.menorca "EP 2019 x Menorca" 2.period "2014-2015 election" post#ep#menorca "EP 2019 x Menorca" 2.period "2014-2015 election") star(* 0.10 ** 0.05 *** 0.01) addnotes("All models include voting station * election type fixed effects" "Standard errors are clustered by voting station * election type") 
